package main;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Calendar;

import communication.BoxInterface;
import communication.messages.SetVolumeMsg;


public class Main {


	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		BoxInterface rmiBox;
		Registry registry;
		
		String server_address = "127.0.0.1";
	    String server_port = "9999";
	    String text = "test message";
	    
	    int volValue = 58;
	    String desc = "descrizione azione VOLUME";
	    Calendar cal = Calendar.getInstance();
	    cal.add(Calendar.MINUTE, 1);
	    
	    SetVolumeMsg msg = new SetVolumeMsg();
	    msg.setTaskStart(null);
	    msg.setDescription(desc);
	    msg.setValue(volValue);
	    
	    System.out.println("Invio: messaggio to " + server_address + ":" + server_port);
		
	    
	    try {
			registry = LocateRegistry.getRegistry(server_address, (new Integer(server_port)).intValue());
			
			rmiBox = (BoxInterface)registry.lookup("rmi_server");
			
			String test = rmiBox.receiveMessage(msg);
	        System.out.println("ricevuta risposta: " + test);
			
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    
	    
	}
	
	
}
